{% extends 'base.html' %}
{% block content %}
<div class="container mt-4">
    <h2>{{ title }}</h2>
    
    <div class="row mb-4">
        <div class="col-md-12">
            <div class="card">
                <div class="card-header">建筑物及传感器数据</div>
                <div class="card-body">
                    <table class="table table-striped">
                        <thead>
                            <tr>
                                <th>建筑物</th>
                                <th>传感器</th>
                                <th>最新监测值</th>
                                <th>监测日期</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% if data_type == 'stress' %}
                                <!-- 应力监测数据展示 -->
                                {% for building in buildings %}
                                    {% for sensor in building.sensors %}
                                    <tr>
                                        {% if forloop.first %}
                                        <td rowspan="{{ building.sensors|length }}">{{ building.name }}</td>
                                        {% endif %}
                                        <td>{{ sensor.name }}</td>
                                        <td>{{ sensor.latest_value }}</td>
                                        <td>{{ sensor.latest_date }}</td>
                                    </tr>
                                    {% endfor %}
                                {% endfor %}
                            {% elif data_type == 'displacement' %}
                                <!-- 位移监测数据展示 -->
                                {% for building in buildings %}
                                    {% for sensor in building.sensors %}
                                    <tr>
                                        {% if forloop.first %}
                                        <td rowspan="{{ building.sensors|length }}">{{ building.name }}</td>
                                        {% endif %}
                                        <td>{{ sensor.name }}</td>
                                        <td>{{ sensor.latest_value }}</td>
                                        <td>{{ sensor.latest_date }}</td>
                                    </tr>
                                    {% endfor %}
                                {% endfor %}
                            {% endif %}
                        </tbody>
                    </table>
                </div>
            </div>
        </div>
    </div>
</div>
{% endblock %}